#!/bin/sh

if [ -z $1 ];then
   hive_db=default
else
   hive_db=$1
fi

if [ -z $2 ];then
   create_time=`date  "+%Y-%m-%d %H-%M-%S"`
else
   create_time=$2
fi

hiveconfig=$(cat <<"EOF" /home/hdfs/parquet_shell/hive_parquet_scripts/hive.config
EOF
)

sql_suffix=$(cat <<EOF 
INSERT INTO TABLE ${hive_db}.navinfo_parquet_0200 PARTITION (part_time, hashtid) SELECT alarm,status,longitude,latitude,originalLng,originalLat,height,speed,direction,gpsDate,mileage,receiveDate,isPatch,oil,recorderSpeed,speedAddition,areaAddition,routeAddition,temAlarm,starStatus,starNumber,alarmIdentify,signalStatus,ioStatus,analogAD0,analogAD1,signalStrength,satelliteNumber,isValid,defenceAddition,parkingAddition,statusAddition,breakdownAddition,additionAlarm,analysisData_turningAngle,analysisData_lowOilDrivingValue,analysisData_vehicleSpeedFromEcu,analysisData_rpmWhenAlarming,analysisData_velocityChangeValue,analysisData_currentGearshift,analysisData_currentRPM,analysisData_deviceIdentity,analysisData_brakeTimes,analysisData_clutchTimes,analysisData_retarderTimes,analysisData_absTimes,analysisData_reverseTimes,batteryPower,moduleVoltages,electricVehicle,batteryInfo_motorTemperature,batteryInfo_motorControlTemp,batteryInfo_mcuFaultCode,batteryInfo_bmsStatus,batteryInfo_batteryAveTem,batteryInfo_batteryCurrent,batteryInfo_totalBatteryV,batteryInfo_batteryFaultCode,batteryInfo_batteryMaxTem,batteryInfo_batteryMinTem,batteryInfo_batteryMinSoc,batteryInfo_maxChargingV,batteryInfo_maxChargingE,batteryInfo_totalStatus,batteryInfo_vehicleSpeed,batteryInfo_shiftStatus,batteryInfo_vcuFaultCode,batteryInfo_enduranceMileage,batteryInfo_acceleratorPedal,batteryInfo_brakePedal,batteryInfo_modelInfo,batteryInfo_switchInfo,batteryInfo_electricAttachment,batteryInfo_motorRpm,alarmFilter,standardMileage,standardFuelCon,staytimeParkingAddition,ecuDate,temperatureAddition_vehType,temperatureAddition_tyrePosition,temperatureAddition_tyreCondition,temperatureAddition_tyrePressure,temperatureAddition_tyreTemperature,temperatureAddition_temAlarmThreshold,temperatureAddition_tyreHalarmThreshold,temperatureAddition_tyreLalarmThreshold,temperatureAddition_tyreNomimalValue,cancleBreakdownAddition,terminalId,stayTime,serialNumber,carLockEffect_engineSpeed,carLockEffect_actualOutputTorque,carLockEffect_throttleOpening,gearStatus,tcuLoad,vecuLoad,ureaInjectionAvg,ureaPressureAvg,transmissionOilTemperature,tcuRamp,engineRunningTime,dpfAshLoading,carbonLoad,totalureaInjection,ureaLevel,newMeterMileage,cargoBoxTemperature1,cargoBoxTemperature2,cargoBoxTemperature3,cargoBoxTemperature4,containerHumidity1,containerHumidity2,containerHumidity3,containerHumidity4,cargoBoxDoorStatus1,cargoBoxDoorStatus2,cargoBoxDoorStatus3,switchStatus,ureaTemperature,gasBox,'${create_time}',part_time, hashtid FROM ${hive_db}.navinfo_stage_0200 distribute by part_time, hashtid;
EOF
)
sql="${hiveconfig}${sql_suffix}"



############  execute begin   ###########
hive --hiveconf "tez.queue.name=hive" -S -e "$sql"
#echo $sql
